📚 node [[python how to write test units|write test units!]]
Welcome! Nobody has contributed anything to 'python how to write test units|write test units!' yet. You can:
  • Write something in the document below!
    • There is at least one public document in every node in the Agora. Whatever you write in it will be integrated and made available for the next visitor to read and edit.
  • Write to the Agora from social media.
    • If you follow Agora bot on a supported platform and include the wikilink [[python how to write test units|write test units!]] in a post, the Agora will link it here and optionally integrate your writing.
  • Sign up as a full Agora user.
    • As a full user you will be able to contribute your personal notes and resources directly to this knowledge commons. Some setup required :)
⥅ related node [[python how to write test units]]
⥅ node [[python-how-to-write-test-units]] pulled by Agora

Fail Fast

When you aren't sure what's going to happen or there's some ambiguity about whether something will work, raise an exception and fail right there and then with an explanation of what went wrong so you can avoid having to dig through fucking tracebacks for 2 hours.

class TestMaintMode:                             			


	@pytest.mark.asyncio									
	
	async def test_maint_mode(self, bot, aresponses):		
	
		# given/prep/arrange								
		
															
		# when/act/do
		

		# then/assert/check
		
  1. Establish test class
  2. Decorator marks test as async
  3. Define sync function
  4. These three are the basic structure of how all tests work

Using Pytest

  1. Create a python file whose name starts with "test_"
  2. Either import or begin the file with the function or functions you'd like to test
  3. Define a number of test functions that take the same arguments as the function/s being tested
  4. assert a call to the function == a certain value that you know should be true
  5. Try cover all possible cases for the function in your tests
  6. Go to the working directory for that file
  7. run the command pytest
  8. Pytest will run and tell you how many tests succeeded and how many failed.
📖 stoas
⥱ context